package com.drg.center.controller;

import com.drg.center.entity.param.SysDictItemAddDTO;
import com.drg.center.entity.param.SysDictItemEditDTO;
import com.drg.center.entity.param.SysDictItemListDTO;
import com.drg.center.entity.result.SysDictItemVO;
import com.guaike.core.entity.result.ItemVO;
import com.guaike.core.entity.result.PageEntity;
import com.guaike.core.entity.result.Result;
import com.drg.center.service.DictItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * @Author: zhangxilin
 * @Date: 2023/10/27
 */
@RestController
@RequestMapping("/dict/item")
@Api(tags = "系统-字典项接口组")
public class SysDictItemController {

    @Autowired
    private DictItemService dictItemService;

    @GetMapping("/findPage")
    @ApiOperation(value = "列表")
    public Result<List<SysDictItemVO>> list(@Valid SysDictItemListDTO param){
        return dictItemService.list(param);
    }

    @PostMapping("/add")
    @ApiOperation(value = "添加")
    public Result<Boolean> add(@Valid @RequestBody SysDictItemAddDTO param){
        return dictItemService.add(param);
    }

    @PostMapping("/edit")
    @ApiOperation(value = "编辑")
    public Result<Boolean> edit(@Valid @RequestBody SysDictItemEditDTO param){
       return dictItemService.edit(param);
    }

    @DeleteMapping("/delete")
    @ApiOperation(value = "删除")
    public Result<Boolean> delete(@ApiParam("ID") @RequestParam("id") Long id){
        return dictItemService.delete(id);
    }

    @PostMapping("/syncCache")
    @ApiOperation(value = "同步全部字典类型到缓存")
    public Result<Boolean> syncCache(){
        dictItemService.syncCache();
        return Result.success().data(Boolean.TRUE).build();
    }

    @GetMapping("/findDict")
    @ApiOperation(value = "查询字典数据")
    public Result<Map<String, List<ItemVO>>> findDict(@ApiParam("字典类型集合") @RequestParam("dictCodeList")  List<String> dictCodeList){
        return dictItemService.findDict(dictCodeList);
    }
}
